package com.example.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.book.entity.Recommend;
import com.example.book.entity.Serial;
import com.example.book.mapper.SerialMapper;
import com.example.book.service.IBookService;
import com.example.book.service.ISerialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-11-15
 */
@Service
@Transactional
public class SerialServiceImpl extends ServiceImpl<SerialMapper, Serial> implements ISerialService {
    @Autowired
    private IBookService bookService;
    @Autowired
    private SerialMapper serialMapper;
    /**
     * 查询图书类型
     *
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public ResponseResult<Page> pageInfo(Integer page, Integer pageSize, String name) {
        Page<Serial> page1 = new Page(page, pageSize);
        LambdaQueryWrapper<Serial> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Serial::getName, name);
        Page<Serial> RecommendPage = this.page(page1, queryWrapper);
        return ResponseResult.okResult(RecommendPage);
    }

    /**
     * 推荐榜图书详细查询
     *
     * @return
     */
    @Override
    public ResponseResult serialAll() {
        Long[] bookIds = serialMapper.selectAllBookIds();
        return ResponseResult.okResult(bookService.bookIdList(bookIds));
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @Override
    public ResponseResult deleteSerial(int[] ids) {
        for (int id : ids) {
            this.removeById(id);
        }
        return ResponseResult.okResult("图书推荐删除成功");
    }
}
